package yyds.sniarbtej.transformer.intellij;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import yyds.sniarbtej.transformer.BaseClassTransformer;
import yyds.sniarbtej.transformer.ClassRewriter;

public final class ChangeExpirationDate extends BaseClassTransformer {
    public String canTransformClassName() {
        return "com/intellij/ui/LicensingFacade";
    }

    public byte[] rewrite(byte[] in) {
        return transform(in, new ClassRewriter() {
            @Override
            public void rewriteMethod(MethodNode node) {
                if ("getLicenseExpirationDate".equals(node.name) && node.desc.equals("()Ljava/util/Date;")) {
                    InsnList insn = new InsnList();
                    insn.add(new VarInsnNode(Opcodes.ALOAD, 0));
                    insn.add(new MethodInsnNode(Opcodes.INVOKESTATIC, methodOverride, "C3", "(Ljava/lang/Object;)Ljava/util/Date;", false));
                    insn.add(new InsnNode(Opcodes.ARETURN));
                    node.instructions.add(insn);
                }
            }
        });
    }
}
